package com.ilearn.limiter.config;


import com.ilearn.limiter.intercepter.RateLimitInterceptor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.context.annotation.Configuration;
import org.springframework.web.servlet.config.annotation.EnableWebMvc;
import org.springframework.web.servlet.config.annotation.InterceptorRegistry;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;

/**
 * @author: lyndon
 * @version: 1.0
 * @date: 2019/3/19
 */

@Slf4j
@Configuration
@EnableWebMvc
public class WebMvcConfig implements WebMvcConfigurer {

    public RateLimitInterceptor getRateLimitInterceptor(){
        return RateLimitInterceptor.getInstance();
    }

    public void addInterceptors(InterceptorRegistry registry) {
        registry.addInterceptor(getRateLimitInterceptor()).addPathPatterns("/user/**");
    }
}
